package go84;

import javax.microedition.lcdui.*;

import com.motorola.iden.lcdui.ExternalDisplay;
import com.motorola.iden.lcdui.ExternalDisplayCanvas;

class ExCanvas extends ExternalDisplayCanvas {
	private Go84 go84class;
	int[] sat={
		1,1,0,1,1,1,1,1,1,1,
		1,0,1,0,1,1,1,0,1,1,
		0,1,0,1,0,1,0,0,0,1,
		1,0,1,0,1,0,0,0,1,1,
		1,1,0,1,0,0,0,1,1,1,
		1,1,1,0,0,0,1,0,1,1,
		1,1,0,0,0,1,0,1,0,1,
		1,0,0,0,1,0,1,0,1,0,
		1,1,0,1,1,1,0,1,0,1,
		1,1,1,1,1,1,1,0,1,1};
	int satWidth=10;
	int satHeight=10;

	public ExCanvas(Go84 go84class) {
		this.go84class=go84class;
		for (int i=0;i<100;i++) {
			sat[i]*=0xffffff;
		}
	}
	protected void paint(Graphics g) {
		String[] extString=go84class.getExtStrings();
		Font f=Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_SMALL);
		g.setFont(f);
		g.setColor(0xffffff);
		g.fillRect(0,0,getWidth(),getHeight());
		g.setColor(0x000000);
		g.drawString(hebString(extString[0]),0,0,g.TOP|g.LEFT);
		g.drawString(extString[1],getWidth(),(getHeight()-f.getHeight())/2,g.TOP|g.RIGHT);
		g.drawString(extString[2],getWidth(),getHeight(),g.BOTTOM|g.RIGHT);
		g.drawString(""+go84class.getSats(),getWidth()-satWidth-1,0,g.TOP|g.RIGHT);
		g.drawRGB(sat, 0, satWidth, getWidth()-satWidth, 0, satWidth,satHeight, false);
	}

	protected void keyPressed(int keyCode) {
		int temp=go84class.getNavInd();
		int size=go84class.getRoute().size();
		if (keyCode==-52) { //vol up
			temp++;
			if (temp>=size)
				temp=-1;
		}
		else if (keyCode==-51) { //vol up
			temp--;
			if (temp<-1)
				temp=size-1;
		}
		go84class.navToPos(temp);
	}

	private String hebString(String str) {
		String strTemp="";
		String strDisp="";
		for (int i=str.length()-1;i>=0;i--) {
			if ((int)str.charAt(i)>1400) {
				strDisp=strDisp+strTemp+str.charAt(i);
				strTemp="";
			}
			else {
				strTemp=str.charAt(i)+strTemp;
			}
		}
		strDisp=strDisp+strTemp;
		return strDisp;
	}
}

